#include "ros/ros.h"
#include "std_msgs/String.h"
#include <sstream>

int main(int argc, char *argv[])
{
    //设置编码
    setlocale(LC_ALL,"");
    //初始化 ros 节点
    ros::init(argc,argv,"A");
    //实例化ros句柄
    ros::NodeHandle nh;
    //实例化发布者对象
    ros::Publisher pub = nh.advertise<std_msgs::String>("fang",10);

    std_msgs::String msg;//定义字符串
    std::string msg_front = "hello";//字符串前半部分
    int count = 0;//计数器

    ros::Rate r(1);//发送频率
    ros::Duration(3.0).sleep();
    while (ros::ok())
    {
        std::stringstream ss;
        ss<<msg_front<<count;
        msg.data = ss.str();
        pub.publish(msg);
        ROS_INFO("send message:%s",msg.data.c_str());
        count++;
        r.sleep();
        // ros::spinOnce();
    }
    return 0;
}

